package org.srtc.infopub.tools;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Map.Entry;


public class QueryResults {

	/**
	 * ���صĽ��
	 */
	private ArrayList<Entry<String, Object>> arr;
	
	/**
	 * ��ǰλ��
	 */
	private int curPos;
	
	
	public QueryResults() {
		arr = new ArrayList<Entry<String, Object>>();
		curPos = 0;
	}
	
	
	/**
	 * ����һ��key���Ӧ�ļ�¼��
	 * @return
	 */
	public int getCount() {
		return 1;
	}
	
	
	public int getSegmentCount() {
		HashSet<String> set = new HashSet<String>();
		for (int i = 0; i<arr.size(); i++) {
			set.add(arr.get(i).getKey());
		}
		return set.size();
	}
	
	
	/**
	 * ������һ��Entry
	 * @return �Ƶ�ĩβ���򷵻�null
	 */
	public Entry<String, Object>  moveNext() {
		++curPos;
		if (curPos > arr.size()) {
			return null;
		}
		return arr.get(curPos-1);
		
	}
	
//	public boolean hasNext()
//	{
//		if (curPos == arr.size() - 1   && arr.size()>0) 
//			return false;
//		return true;
//	}
//	
//	public Entry<String, Object> getValue()
//	{
//		if (curPos > arr.size()) {
//			return null;
//		}
//		return arr.get(curPos);
//	}
	
	/**
	 * �������е��ֶ�
	 * @return
	 */
	public ArrayList<String> getSegments() {
		ArrayList<String> set = new ArrayList<String>();
		for (int i = 0; i<arr.size(); i++) {
			if (set.contains(arr.get(i))) {
				continue;
			}
			set.add(arr.get(i).getKey());
		}
		return set;
	}
	
	
	/**
	 * ���segName����ֵ
	 * @param segName
	 * @return �޸��ֶη���null
	 */
	public Object getValue(String segName) {
		for (int i = 0; i<arr.size(); i++) {
			if (arr.get(i).equals(segName)) {
				return arr.get(i);
			}
		}
		return null;
	}
	
	
	/**
	 * 
	 * @param index ��0��ʼ
	 * @return index���ڵ���size�򷵻�null
	 */
	public Object getValue(int index) {
		if (arr.size() == 0 || arr.size() >= index) {
			return null;
		}
		return arr.get(index);
	}
	
	
	public ArrayList<Entry<String, Object>> getArr() {
		return arr;
	}
	
	
	public String toString() {
		String line = "";
		for (int i = 0; i<arr.size(); i++) {
			line = line + arr.get(i) + "\t";
		}
		return line;
	}


	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
